home *** CD-ROM | disk | FTP | other *** search
/ Merciful 5 / Merciful - Disc 5.iso / software / h / hypertextdatav40.12cr.lha / HTDS / ARexx / AddTOCEntry.rexx next >
Encoding:
OS/2 REXX Batch file  |  1996-12-31  |  4.9 KB  |  195 lines

  1. /*
  2. ** $PROJECT: HyperText-DataType-System
  3. **
  4. ** $VER: AddTOCEntry.rexx 40.5 (30.12.96)
  5. **
  6. ** by
  7. **
  8. ** Stefan Ruppert , Windthorststrasse 5 , 65439 Floersheim , GERMANY
  9. **
  10. ** (C) Copyright 1996
  11. ** All Rights Reserved !
  12. **
  13. ** $HISTORY:
  14. **
  15. ** 30.12.96 : 040.005 : added FLUSH command and UniView support
  16. ** 27.10.96 : 040.004 : use rexxdossupport.library
  17. ** 16.09.96 : 040.003 : added some comments
  18. ** 31.08.96 : 040.002 : added NODENAME field
  19. ** 29.08.96 : 040.001 : initial
  20. **
  21. */
  22.  
  23. Options Results
  24.  
  25. Parse Arg args
  26.  
  27. /* --------------------------- needed libraries --------------------------- */
  28.  
  29. Call AddLib('rexxsupport.library',0,-30,0)
  30. Call AddLib('rexxdossupport.library',0,-30,0)
  31.  
  32. Parse Arg args
  33.  
  34. rxport        = ''
  35. stem.title    = ''
  36. stem.path     = ''
  37. stem.nodename = ''
  38. stem.verbose  = 0
  39. stem.debug    = 0
  40.  
  41. If ReadArgs(args,'TITLE,PATH,NODENAME,VERBOSE/S,DEBUG/S','STEM.') Then Do
  42.  
  43.    /* if no arguments are given from command line, try to get information
  44.     * from MultiView. This uses the hypertext.datatype ARexx port.
  45.     */
  46.    If stem.title = '' | stem.path = '' Then Do
  47.       rxport = ADDRESS()
  48.       if Right(rxport,4) ~= '.1.1' Then
  49.      rxport = rxport || '.1'
  50.  
  51.       If ~Show(Ports,rxport) Then
  52.       Do
  53.      rxport = 'UNIVIEW.1.1'
  54.  
  55.      If ~Show(Ports,rxport) Then
  56.      Do
  57.         rxport = 'MULTIVIEW.1.1'
  58.         If ~Show(Ports,rxport) Then
  59.         Do
  60.            rxport = 'HYPERTEXTDT.1'
  61.            If ~Show(Ports,rxport) Then
  62.            Do
  63.           Say 'Multiview not started or displays a none HyperText object'
  64.           Exit 10
  65.            End
  66.         End
  67.      End
  68.       End
  69.  
  70.       If (stem.verbose) Then
  71.      Say rxport
  72.  
  73.       ADDRESS VALUE rxport
  74.  
  75.       /* Obtain current object information */
  76.       'GETATTR OBJECT=OBJECT FIELD=TITLE    VAR="STEM.TITLE"'
  77.       'GETATTR OBJECT=OBJECT FIELD=PATH     VAR="STEM.PATH"'
  78.       'GETATTR OBJECT=OBJECT FIELD=NODENAME VAR="STEM.NODENAME"'
  79.    End
  80.  
  81.    If (stem.verbose) Then
  82.    Do
  83.       Say stem.path
  84.       Say stem.title
  85.       Say stem.nodename
  86.    End
  87.  
  88.    /* Get Global TOC file name */
  89.    tocfile = 'Help:' || GetVar('Language') || '/HTDS_TOC.hguide'
  90.    tmpfile = 'T:ate' || Time(s)
  91.  
  92.    file     = Strip(Trim(stem.path))
  93.    title    = Strip(Trim(stem.title))
  94.  
  95.    filename = FilePart(file)
  96.    letter   = Upper(Left(Strip(filename),1))
  97.  
  98.    if Length(stem.nodename) > 0 Then Do
  99.       If Right(file,1) ~= ':' & Right(file,1) ~= '/' Then
  100.      file = file || '/'
  101.       file = file || stem.nodename
  102.    End
  103.  
  104.    /* try to flush the TOC file from the hypertext object */
  105.    If (rxname ~= '') Then
  106.    Do
  107.       If stem.verbose Then
  108.      Say 'Flush ' || tocfile
  109.       'FLUSH DOCUMENT="' || tocfile || '"'
  110.    End
  111.  
  112.    /* add a entry in the global table of contents file, sorted by the initial
  113.     * letter.
  114.     *
  115.     * Implemented as a state machine.
  116.     */
  117.  
  118.    state = ''
  119.    If Open('tmp',tmpfile,'w') Then Do
  120.       If Open('toc',tocfile,'r') Then Do
  121.      state = 'begin'
  122.      Do While ~Eof('toc')
  123.         line = ReadLn('toc')
  124.  
  125.         If (stem.debug) Then Do
  126.            Say 'State : ' || state
  127.            Say Line
  128.         End
  129.  
  130.         Select
  131.            When state = 'begin' Then Do
  132.           /* search for the beginning of the link section */
  133.           If line = '@remark HTDS_TOC BEGIN' Then
  134.              state = 'table'
  135.           Call WriteLn('tmp',line)
  136.            End
  137.            When state = 'table' Then Do
  138.           /* now search for the appropriate initial letter */
  139.           If Left(line,11) = '@{m_letter ' Then Do
  140.              If SubStr(line,12,1) = letter Then
  141.             state = 'insert'
  142.              Else if SubStr(line,12,1) > letter Then Do
  143.             Call WriteLn('tmp','@{m_letter ' || letter || '}')
  144.             Call WriteLn('tmp','@{" ' || filename || ' " link "' || file || '"}@{tab}' || title)
  145.             Call WriteLn('tmp','')
  146.             state = 'end'
  147.              End
  148.  
  149.              Call WriteLn('tmp',line)
  150.           End
  151.           Else If line = '@remark HTDS_TOC END' then Do
  152.              /* now entry found with the same letter, just append the current one */
  153.              Call WriteLn('tmp','@{m_letter ' || letter || '}')
  154.              Call WriteLn('tmp','@{" ' || filename || ' " link "' || file || '"}@{tab}' || title)
  155.              Call WriteLn('tmp','')
  156.              state = 'end'
  157.  
  158.              Call WriteLn('tmp',line)
  159.           End
  160.           Else
  161.              Call WriteLn('tmp',line)
  162.            End
  163.            When state = 'insert' Then Do
  164.           /* there exist some entries with the same initial letter, now sort
  165.            * it within these entries
  166.            */
  167.  
  168.           Parse Var line '@{" ' linefilename ' " link "' linkname '"}@{tab}' rest
  169.           rest = Strip(Trim(rest))
  170.           linefilename = Strip(Trim(linefilename))
  171.           If line = '' | Upper(filename) <= Upper(linefilename) Then Do
  172.              If (linefilename ~= filename) | (rest ~= title) Then
  173.             Call WriteLn('tmp','@{" ' || filename || ' " link "' || file || '"}@{tab}' || title)
  174.              state = 'end'
  175.           End
  176.           Call WriteLn('tmp',line)
  177.            End
  178.            When state = 'end'   Then Do
  179.           Call WriteLn('tmp',line)
  180.            End
  181.         End
  182.      End
  183.      Call Close('toc')
  184.       End
  185.       Call Close('tmp')
  186.    End
  187.    If state = 'end' Then
  188.       Address Command 'Copy ' || tmpfile || ' TO ' || tocfile ' QUIET'
  189.  
  190.    Address Command 'Delete ' || tmpfile || ' QUIET'
  191. End
  192.  
  193. Exit
  194.  
  195.